package com.hy.study.driver;

import com.hy.study.mapper.Log2Mapper;
import com.hy.study.mapper.LogMapper;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

/**
 * @author huyong
 * @date 2024 年 02 月 06 日 16:01: 40
 */
public class LogDriver {
    public static void main(String[] args) throws Exception {
        final String inputfile = "F:\\study\\Hadoop\\input\\logs";
        final String outputfile = "F:\\study\\Hadoop\\output\\result7";
        // 1 获取job信息
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf);

        // 2 加载jar包
        job.setJarByClass(LogDriver.class);

        // 3 关联map
        job.setMapperClass(Log2Mapper.class);

        // 4 设置最终输出类型
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(NullWritable.class);

        // 设置reducetask个数为0
        job.setNumReduceTasks(0);

        // 5 设置输入和输出路径
        FileInputFormat.setInputPaths(job, new Path(inputfile));
        FileOutputFormat.setOutputPath(job, new Path(outputfile));

        // 6 提交
        job.waitForCompletion(true);
    }

}
